package com.gtworldmobile.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.KeyEvent;
import android.view.MotionEvent;

import com.gtworld.android.slideout.SlideoutHelper;
import com.gtworldmobile.design.SimpleGestureFilter;
import com.gtworldmobile.design.SimpleGestureFilter.SimpleGestureListener;

public class MenuActivity extends FragmentActivity implements
		SimpleGestureListener {

	private SlideoutHelper mSlideoutHelper;
	private SimpleGestureFilter detector;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mSlideoutHelper = new SlideoutHelper(this);
		mSlideoutHelper.activate();
		getSupportFragmentManager()
				.beginTransaction()
				.add(com.gtworld.android.slideout.R.id.slideout_placeholder,
						new MenuFragment(), "menu").commit();
		mSlideoutHelper.open();
		detector = new SimpleGestureFilter(this, this);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			mSlideoutHelper.close();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public SlideoutHelper getSlideoutHelper() {
		return mSlideoutHelper;
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent me) {
		this.detector.onTouchEvent(me);
		return super.dispatchTouchEvent(me);
	}

	@Override
	public void onSwipe(int direction) {

		switch (direction) {

		case SimpleGestureFilter.SWIPE_RIGHT:
			// Nothing to do
			break;
		case SimpleGestureFilter.SWIPE_LEFT:
			mSlideoutHelper.close();
			break;
		case SimpleGestureFilter.SWIPE_DOWN:
			// Nothing to do
			break;
		case SimpleGestureFilter.SWIPE_UP:
			// Nothing to do
			break;

		}

	}

	@Override
	public void onDoubleTap() {
		// Nothing to do

	}
}
